#import "Mail.h"

@implementation Mail
@synthesize sender = _sender;
@synthesize date = _date;
@synthesize size = _size;
@synthesize subject = _subject;
@synthesize content=_content;
@synthesize fullSender=_fullSender;
@synthesize receiver=_receiver;
@synthesize UNID=_UNID;
@synthesize attachmentName=_attachmentName;
@synthesize hasAttachment=_hasAttachment;

- (Mail *)init
{
	[super init];
	_hasRead=NO;
	_hasContentDownloaded=NO;
	_hasAttachment=NO;
	self.sender=@"";
	self.subject=@"";
	return self;
}

- (Boolean )hasRead
{
	return _hasRead;
}


- (Boolean )hasContentDownloaded
{
	return _hasContentDownloaded;
}

- (void)markRead
{
	_hasRead=YES;
}

- (void)markDownload
{
	_hasContentDownloaded=YES;
}

#pragma mark file handling
static NSString* mailEntrySplitSymbol=@" #___# ";// use this symbol to split different attributes, for example, "sender #___# size"
//Load Mail Attributes from file format
- (id)initWithAttributes:(NSString *)Attributes
{
    NSArray* attribute=[Attributes componentsSeparatedByString:mailEntrySplitSymbol];
	_sender=[[attribute objectAtIndex:0] retain];
	_date=[[NSDate alloc] initWithString:[attribute objectAtIndex:1]];
	_size=[[attribute objectAtIndex:2] retain];
	_subject=[[attribute objectAtIndex:3] retain];
	_hasAttachment=[[attribute objectAtIndex:4] boolValue];
	_hasRead=[[attribute objectAtIndex:5] boolValue];
	_fullSender=[[attribute objectAtIndex:6] retain];
	_receiver=[[attribute objectAtIndex:7] retain];
	_UNID=[[attribute	objectAtIndex:8] retain];
	_content=[[attribute objectAtIndex:9] retain];
	_hasContentDownloaded=[[attribute objectAtIndex:10] boolValue];
	_attachmentName=[[attribute objectAtIndex:11] retain];
	return self;
}

//Save Mail Attributes to file format
- (NSString *)attributes
{
	NSString* newAttribute=[NSString stringWithFormat:@"%@%@%@%@%@%@%@%@%hi%@%hi%@%@%@%@%@%@%@%@%@%hi%@%@",_sender, mailEntrySplitSymbol,
					[_date description] , mailEntrySplitSymbol, _size, mailEntrySplitSymbol, _subject, mailEntrySplitSymbol,_hasAttachment, 
					 mailEntrySplitSymbol, _hasRead, mailEntrySplitSymbol, _fullSender, mailEntrySplitSymbol, _receiver, mailEntrySplitSymbol,
					_UNID,  mailEntrySplitSymbol,_content,  mailEntrySplitSymbol, _hasContentDownloaded,mailEntrySplitSymbol,_attachmentName];
    return newAttribute;
}

@end
